<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<title>RestoReceta - Administaci&oacute;n</title>
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />

	<link rel="stylesheet" type="text/css" href="css/demo_table.css" />
	
	<link rel="stylesheet" type="text/css" href="css/tabla2.css" />
	<link rel="stylesheet" type="text/css" href="css/admin.css" />	
	<link rel="stylesheet" type="text/css" href="css/superfish.css" media="screen"/>
	<link rel="stylesheet" type="text/css" href="css/superfish-vertical.css" media="screen"/>
	<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
	
	
	
	<?php

		if (empty($jotaeses)) $jotaeses=array();
		foreach($jotaeses as $js){
			echo '<script type="text/javascript" src="js/'.$js.'"></script>';
		}
	?>	
	
	<script type="text/javascript">
		var idpregunta='';
		var tabla='';
		var opcion=0;
	</script>

	<script type="text/javascript">
		$(function() { 
			$(document).ready(function(){ 
				$("ul.sf-menu").superfish(); 
			}); 
		});
	</script>
		
		<script type="text/javascript">
			function verify(){
				<?
				if (isset($cuerpo['form']['verify'])){
					echo $cuerpo['form']['verify'];
				}else{
					echo 'return true;';
				}		
				?>
			}
			
			function logout(){
				if (confirm("¿Desea salir del sistema?")){
					window.location ="auth/logout.php";
				}
			}
			
			function popitup(url) {
				newwindow=window.open(url,'name','height=360,width=600');
				if (window.focus) {newwindow.focus()}
				return false;
			}
		</script>

</head>
<?php
	$estilo= (!isset($cuerpo['downtab']))?'height:100%;':'';
?>
<body>
	<div id="container" style="<?=$estilo?>">
		<div id="upper">
			<?php
			global $restaurants;
			if (isset($restaurants)){ 
				echo '<div id="restaurant"> Restaurant: ';
				if(count($restaurants)>1){
					echo '<select id="restos" onchange="changeResto()" >';
					foreach($restaurants as $key=>$resto){
						$selected=($key==$_SESSION['Restaurant_ID'])?'selected="selected"':'';
						echo '<option value="'.$key.'" '.$selected.' >'.$resto.'</option>';
					}
					echo '</select>';
				}else{
					echo array_pop($restaurants);
				}	
				echo '</div>';		
			}		
			?>
			<div id="username"><?=$usuario?> [<a onclick="logout()">log out</a>]</div>
		</div id="upper">
		<div id="menu">
			<div style="float:left;clear:both; margin-left:25px; letter-spacing:5px; font-family:monospace; font-size:36pt; font-weight:bold; color:#FFFFFF;">RR</div>
			<div style="float:left;clear:both; margin-left:25px; margin-top:-10px; margin-bottom:10px;  font-weight:bold; color:#FFFFFF; font-family:monospace;">admin</div>
			<div style="float:left;clear:both;"> </div>			
			
			<?	if (empty($menu)) $menu=array(); ?>
			<ul class="sf-menu sf-vertical">
			<?	foreach ($menu as $tag=>$item){
					if (is_array($item)){
						echo '<li><a href="#">'.$tag.'</a><ul>';
						foreach ($item as $ki=>$ti){
							$toolTip=(isset($hint[$tag][$ki]) && !empty($hint[$tag][$ki]) )?"onmouseout=\"tooltip.hide();\" onmouseover=\"tooltip.show('".$hint[$tag][$ki]."')\";":'';
							echo '<li><a href="'.$ti.'" '.$toolTip.'>'.$ki.'</a></li>';
						}
						echo '</ul></li>';
					}else{
						$toolTip=(isset($hint[$tag]) && !empty($hint[$tag]) )?"onmouseout=\"tooltip.hide();\" onmouseover=\"tooltip.show('".$hint[$tag]."')\";":'';
						echo '<li><a href="'.$item.'" '.$toolTip.'>'.$tag.'</a></li>';
					}
				} 
			?>
			</ul>
		</div>	
		
		<div id="cuerpo">
			<?	if (empty($cuerpo)) $cuerpo=array();
				
				if (isset($cuerpo['msg'])) { ?>
					<div id="msg"> <?=$cuerpo['msg']; ?> </div>
					
			<?	}
				
				if (isset($cuerpo['tablas'])){
	
					foreach($cuerpo['tablas'] as $kt=>$tabla){ ?>
						<div class="tabla" >
							<div class="titulo"> <?=$tabla["titulo"]?> </div>
							<?if (isset($cuerpo['filtro'])) {?>
								<select id="<?=$cuerpo['filtro']['name']?>">
									<? foreach ($cuerpo['filtro']['opc'] as $ko=>$opc){
										echo "<option value='".$ko."'>".$opc."</option>";
									} ?>						
								</select>
						<?	}?>
							<table id="<?=$kt?>">
							<thead>
							<tr>
							<?	foreach ($tabla['metadata'] as $nomcol){
									echo '<th>'.$nomcol.'</th>';
								}?>
							</tr>
							</thead>
							<tbody>
							<?	foreach ($tabla['data'] as $idp=>$fila){ ?>
									<? $clase= (isset($tabla['clase'][$idp]))? $tabla['clase'][$idp]:''; ?>
									<tr id="fila_<?=$idp?>" class="filaselec <?=$clase?>">
									<?	foreach($fila as $celda){
											echo '<td>'.$celda.'</td>';
										} ?>
									</tr>
							<?	} ?>
							</tbody>
							</table>
						</div class="tabla">
						<br />
						<hr />
				<?	}
				}
				$form='';
				if (isset($cuerpo['form'])){
					$form.= '<div class="formulario">';
					$form.= '<div class="titulo">'.$cuerpo['form']['titulo'].'</div>';
					if (!isset($cuerpo['form']['target'])) $cuerpo['form']['target']='_self';
					if (!isset($cuerpo['form']['style'])) $cuerpo['form']['style']='';
					$form.= '<form name="form1" method="post" action="'.$cuerpo['form']['action'].'" target="'.$cuerpo['form']['target'].'" onSubmit="return verify()" onKeyPress="return disableEnterKey(event)" style="'.$cuerpo['form']['style'].'">';
					$size=count($cuerpo['form']['elements']);
					$i=0;
					foreach($cuerpo['form']['elements'] as $element){
						$i++;
						if (isset($cuerpo['form']['add']) && $size==$i) $form.= $cuerpo['form']['add'];		
						
						$value=(isset($element['value']))?$element['value']:'';
						$class=(isset($element['class']))?$element['class']:'';	
						$name=(isset($element['name']))?$element['name']:'';	
						$id=(isset($element['id']))?$element['id']:'';
						
						//$aux='<input type="'.$element['type'].'" name="'.$name.'" value="'.$value.'" class="'.$class.'" />';
						$start='';
						$end='';
						$autoJS='';
						switch ($element['type']) {
							case 'textarea':
								$start='<textarea id="'.$id.'" ';
								$end='>'.$value.'</textarea>';	
								break;	
							case 'select':
								$start='<select id="'.$id.'" ';
								$end='>';
								foreach ($value as $k=>$opt){
									$end.='<option value="'.$k.'">'.$opt.'</option>';
								}
								$end.='</select>';	
								break;									
							case 'label':
								$start='<label id="'.$id.'" ';
								$end='>'.$value.'</label>';	
								break;
							case 'autocomplete':
								$start='<input id="'.$id.'" type="hidden" value=""/> <input id="'.$id.'Text" type="text"';
								$end='/>';	
								$autoJS.='$("#'.$id.'Text").autocomplete("autocompletarIngrediente.php", {
												width: 260,
												selectFirst: true,
												mustMatch: true,
												matchContains: true,
												max: 15
											});
											$("#'.$id.'Text").result(function(event, data, formatted) {
												if (data){	
													$("#'.$id.'").val(data[1]); 
													$("#unidad1").html(" $"+ preciosIngr[data[1]] +" x " + unidadesIngr[data[1]] );
												}
											});';
								break;
							default:
								$start='<input id="'.$id.'" type="'.$element['type'].'"  value="'.$value.'" ';
								$end='/>';							
						}

						$start.=' name="'.$name.'" ';
						if (isset($element['label']) && !empty($element['label'])){
							$start='<div class="'.$class.'">
									<div class="etiqueta"><label>'.$element['label'].'</label></div>
									'.$start;
							$end.=' </div>';						
						}else{
							$start.=' class="'.$class.'" ';
						}
						if(isset($element['readonly'])){
							$start.=' readonly="'.$element['readonly'].'" ';
						}
						
						$form.= $start.$end.'
						';
						if(!empty($autoJS)) $form.='<script type="text/javascript">'.$autoJS.'</script>';
						
					}	
					if (isset($cuerpo['form']['free']))	$form.= $cuerpo['form']['free'];						
					$form.= '</form>';
				}
				if (isset($cuerpo['downtab'])){
					echo $form;
				}
				
				if (isset($cuerpo['plano'])){
					echo $cuerpo['plano'];
				}
				
			?>
			<div style="height:350px"></div>
		</div id="cuerpo">	
		
		<div id="pie">
		<?	if (empty($pie)) $pie='';
			echo $pie;
		?>
			<div style="height:50px; width:100%;"></div>
		</div id="pie">
		
		
	</div id="container">
<?	
	if (isset($cuerpo['downtab'])){
		echo $cuerpo['downtab'];
	}elseif (!empty($form)){
		echo '<div id="ajaxtag" ><div id="ajxleft"></div><div id="ajxright">'.$form.'</div>';
	}else{ 
	}
				
				?>
	
	<script type='text/javascript'>
		<?	foreach($scripts as $script){
				echo $script;
				echo '
				';
			} ?>
	</script>
	
	<script type="text/javascript">
		$('.filaselec').click(function() {
			$('.filaselec').removeClass('negrita');
			$(this).addClass('negrita');
		});		

	</script>
	<?if (isset($cuerpo['downtab']) || !empty($form)){ ?>
		<div id="close_tab"><img src="imagenes/down_tab.png"/></div>
		<div id="open_tab"><img src="imagenes/up_tab.png"/></div>
		<script type="text/javascript">
			$('#ajaxtag').addClass('ajaxup');
			$('#close_tab').addClass('closeup');
			$('#open_tab').addClass('closeup');
			$('#container').addClass('containersmall');
			estadoTab=1;//0:abajo, 1:intermedio, 2:arriba 
			$('#close_tab').click(function() {
				switch (estadoTab){
					case 1:
						$('#ajaxtag').removeClass('ajaxup').addClass('ajaxdown');
						$('#close_tab').html('');
						$('#close_tab').removeClass('closeup').addClass('closedown');
						$('#container').removeClass('containersmall').addClass('containerbig');
						$('#open_tab').removeClass('closeup').addClass('closedown');
						estadoTab=0;
						break;
					case 2:
						$('#open_tab').html('<img src="imagenes/up_tab.png"/>');
						$('#ajaxtag').removeClass('ajaxall').addClass('ajaxup');
						$('#close_tab').removeClass('closeall').addClass('closeup');
						$('#container').removeClass('containertiny').addClass('containersmall');
						$('#open_tab').removeClass('closeall').addClass('closeup');
						estadoTab=1;				
				}
			});
			$('#open_tab').click(function() {
				switch (estadoTab){
					case 0:
						$('#ajaxtag').removeClass('ajaxdown').addClass('ajaxup');
						$('#close_tab').html('<img src="imagenes/down_tab.png"/>');
						$('#close_tab').removeClass('closedown').addClass('closeup');
						$('#container').removeClass('containerbig').addClass('containersmall');
						$('#open_tab').removeClass('closedown').addClass('closeup');
						estadoTab=1;
						break;
					case 1:
						$('#open_tab').html('');
						$('#ajaxtag').removeClass('ajaxup').addClass('ajaxall');
						$('#close_tab').removeClass('closeup').addClass('closeall');
						$('#container').removeClass('containersmall').addClass('containertiny');
						$('#open_tab').removeClass('closeup').addClass('closeall');
						estadoTab=2;				
				}
			});
			
			
		</script>
		
	<? } ?>	
	
<div id="waiting" class="escondido"><div id="text">Por favor espere un momento</div><img src="imagenes/loadinfo.gif" /></div>
		
<script type="text/javascript">
	function changeResto(){ 
		$.post('cambiarResto.php', {idresto:$("#restos").val()}, function(data) {
			if (data=='1'){
				window.location.reload();
			}else{
				alert(data);
			}
		});
	}
</script>

</body>
	
</html>
